#ifndef CUSTOMMOTO_H
#define CUSTOMMOTO_H

#include <QString>
#include <QWidget>
#include "../TableWidgetForm.h"

struct ConnectStr
{
    QString name;
    QString type;

    // 获取结构体成员名的字符串
    QString toFieldNames() const {
        return QString("name,type");
    }

    // 获取结构体成员名的字符串
    QStringList toFieldTypes() const {
        QStringList _list;
        _list << typeid(name).name();
        _list << typeid(type).name();
        return _list;
    }
};

struct MotoStruct
{
    int id;
    QString name;
    int currentlocation;
    int minstep;
    int maxstep;
    int steppos;
    int maxspeed;
    int minspeed;
    int movespeed;
    int openpos;
    int closepos;
    int findzerotimes;
    int minacc;
    int rigidity;
    int timeinterval;
    int zeroposition;
    int zerostepover;
    int timerinterval;
    int enable;

    // 获取结构体成员名的字符串
    QString toFieldNames() const {
        return QString("name,currentlocation,minstep,maxstep,steppos,maxspeed,minspeed,movespeed,openpos,closepos,findzerotimes,minacc,rigidity,"
                       "timeinterval,zeroposition,zerostepover,timerinterval,enable");
    }

    // 获取结构体成员名的字符串
    QStringList toFieldTypes() const {
        QStringList _list;
        _list << typeid(name).name();
        _list << typeid(currentlocation).name();
        _list << typeid(minstep).name();
        _list << typeid(maxstep).name();
        _list << typeid(steppos).name();
        _list << typeid(maxspeed).name();
        _list << typeid(minspeed).name();
        _list << typeid(movespeed).name();
        _list << typeid(openpos).name();
        _list << typeid(closepos).name();
        _list << typeid(findzerotimes).name();
        _list << typeid(minacc).name();
        _list << typeid(rigidity).name();
        _list << typeid(timeinterval).name();
        _list << typeid(zeroposition).name();
        _list << typeid(zerostepover).name();
        _list << typeid(timerinterval).name();
        _list << typeid(enable).name();
        return _list;
    }
};

class CustomMoto
{
public:
    CustomMoto();

    //初始化UI
    static void InitUI(const QString& fileName, QList<QPair<QWidget *, QString>>& widgets, QMap<int, QList<TableWidgetForm*>>& m_pTableWidgetFormMap);

    //保存
    static bool SaveUI(const QString& fileName, const QMap<int, QList<TableWidgetForm*>>& m_pTableWidgetFormMap);

    //解析
    static void Analysis(const QString& path, ConnectStr& str, QList<MotoStruct>& motos);

    //保存
    static bool SaveXml(const QString& path, const ConnectStr& str, const QList<MotoStruct>& motos);
};

#endif // CUSTOMMOTO_H
